#include "core.hpp"
#include "Frame/states.hpp"
#include "IO/io.hpp"

App::App(States *_state, WorkType _type):Process(_state, _type)
{
	Log("Create core~");
	o1 = 0;
	o2 = 0;
	o3 = 0;
	o4 = 0;
	o5 = 0;

	oe = 0;

	if (this->w_type > W_ImagePairs)
	{
		//o1 = new Saliency(this);
		//o2 = new KLT(this);
		//o3 = new Track(this, _state);
		//o4 = new Cali(this, _state);
        //o5 = new Face(this, _state);

        oe = new Show(this, _state);
	}
}

App::~App()
{
	Log("Release core");

	if(o1!=0)
		delete o1;
	if(o2!=0)
		delete o2;
	if(o3!=0)
		delete o3;
	if(o4!=0)
		delete o4;
    if(o5!=0)
        delete o5;

    if(oe!=0)
        delete oe;

	if(prv_image.data !=0 && w_type != W_ImageOne)
		prv_image.Release();
	//if(rst_image.data !=0)
	//	rst_image.Release();
}

void App::ToDo(const Image &image)
{
	if(prv_image.data==0)
			prv_image = Image(image.width, image.height, 3);
	/*
	if(rst_image.data!=0)
		rst_image.Release();
	rst_image = Image(image.width, image.height, 3);
	*/
	if(m_count != 0 && w_type != W_ImageOne)
	{
		if(o1!=0)
			model->Get(o1->out_image);
		//if(o2!=0)
			//model->Get(); // 更改到model中记录结果

		if(o3!=0)
		{
			//std::cout << o3->TrackBox.size() << std::endl;
			model->Get(o3->TrackBox);
		}

		if(o4!=0)
			model->Get(o4->CaliBox);

		if(o5!=0)
		{
			model->Get(o5->CaliBox);
			//std::cout << o5->CaliBox.x << "," << o5->CaliBox.y << std::endl;
			model->Get(o5->CaliPoint);
		}
		if(oe!=0)
		{
			model->Get(oe->out);
		}
	}

}
